<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>jQuery UI Accordion - Customize icons</title>
	<link type="text/css" rel="stylesheet" href="CSS/jquery.ui.all.css"> 
    <link href="CSS/demos.css" rel="stylesheet" type="text/css">		
    <link type="text/css" href="CSS/jquery-ui-1.8.20.custom.css" rel="stylesheet" >	
    <link type="text/css" href="CSS/addtion.css" rel="stylesheet">	
	 <script type="text/javascript"  src="Scripts/json2.js"></script>
    <script type="text/javascript" src="Scripts/ServletAddress.js"></script>
	<script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="Scripts/ui/jquery.ui.core.js"></script>
	<script type="text/javascript" src="Scripts/ui/jquery.ui.widget.js"></script>
	<script type="text/javascript" src="Scripts/ui/jquery.ui.accordion.js"></script>
	<script type="text/javascript" src="Scripts/ui/jquery.ui.button.js"></script>	
	<script type="text/javascript" src="Scripts/addtion.js"></script>
    <script>
	//**************************My Methods****************************
	function addTitle()
	{
		var Item=
			"<button class='titleBox' id='toggle'>信息窗</button>";			
			$("body").append(Item);	
	}
	function removeItems() 
	{
		$("h3").remove();
		
		$(".lists").remove();
	}
	function getID(id)
	{		
		var hid=parseInt(id)						
		//flyToGeometry(hid);
		window.parent.document.frames["mainFrame"].FlyToGeometry(hid);	
		window.parent.document.frames["mainFrame"].removeSelect3D();
		window.parent.document.frames["mainFrame"].addSelect3D(id);
		
	}
	function addItem(id,premise)
		{
			//记得把房屋的ID赋值给此元素的ID，这样点击的时候可以获取房屋的ID，然后飞行到指定的位置
			var Item=
			"<h3 class='itemStyle' id="+id+"  onClick='getID("+id+")';><a>"+premise+"</a></h3>";			
			$("#accordion").append(Item);	
			
		}
	function addItem2(id,premise)
		{
			//记得把房屋的ID赋值给此元素的ID，这样点击的时候可以获取房屋的ID，然后飞行到指定的位置
			var Item=
			"<h3 class='itemStyle' id="+id+"><a>"+premise+"</a></h3>";			
			$("#accordion").append(Item);	
			
		}
	function addSubItem(area,price,type,location)
		{
			//记得把房屋的ID赋值给此元素的ID，这样点击的时候可以获取房屋的ID，然后飞行到指定的位置
			var Item="<div class='lists'>	<ul class='subItemStyle'> <li>面积："+area+"</li><li>价格："+price+"</li><li>户型："+type+"</li><li>地理位置："+location+"</li></ul></div>";			
			$("#accordion").append(Item);				
		}
	function addSubItem3(area,price,type,location,arrow,floor)
		{
			//记得把房屋的ID赋值给此元素的ID，这样点击的时候可以获取房屋的ID，然后飞行到指定的位置
			var Item="<div class='lists'>	<ul class='subItemStyle'> <li>面积："+area+"</li><li>价格："+price+"</li><li>户型："+type+"</li><li>楼层：第"+floor+"层</li><li>地理位置："+location+"</li><li>朝向：朝"+arrow+"方向</li></ul></div>";			
			$("#accordion").append(Item);				
		}
	function addSubItem2(text)
		{
			//记得把房屋的ID赋值给此元素的ID，这样点击的时候可以获取房屋的ID，然后飞行到指定的位置
			var Item="<div class='lists'><p>"+text+"</p></div>";			
			$("#accordion").append(Item);				
		}
	function addEvent()
		{
			$( "#accordion" ).accordion({
					create: function(event, ui) {},
					autoHeight: false,
					navigation: true
					});
		}
	function destroyEvent()
		{
			$( "#accordion" ).accordion("destroy");	
		}
	function resize()
	{
		$( "#accordion" ).accordion( "resize" );
	}
	//**************************End My Methods****************************

	
$(function() {			
	//***********Order Methods**************
			
			jQuery(window.parent.frames["LeftFrame"].document).find("#myFavor").click(function(){
			
			removeItems();
			destroyEvent();			
			var uid= window.parent.document.frames["login"].session;	
		//alert(uid);				
			if(uid!=null)
			{
				//取消所有选中状态
				window.parent.document.frames["mainFrame"].removeSelect3D();
				//addTitle();
				jQuery(window.parent.frames["rightFrame"].document).find(".titleBox").html("我的收藏");						
				//Button Toggle
				$( "#toggle" ).button().toggle(function() {
				$( "#accordion" ).accordion( "option", "icons", false );
					}, function() {
				$( "#accordion" ).accordion( "option", "icons", icons );
					});	
				//End Button toggle
				jQuery(window.parent.document).find("#rightFrame").fadeIn(1000);                                
				jQuery(window.parent.document).find("#rightFrame").animate({ width: 240}, 1000 );
				jQuery(window.parent.frames["rightFrame"].document).find("#SPIC").attr("src","images/rightslide.png");	
				//情况原来的查询结枿			
				/////////////												
				jQuery.getJSON(ServletAddress+getFavorAddress+"UID="+uid,function(jsresult){				
					resultCount=jsresult.length;
					if(jsresult.length<=10)
					{
						len=jsresult.length;
					}
					else
					{
						len=10;
					}
					lastIndex=resultCount-1;
					firstIndex=resultCount-len-1;
					for(var i=lastIndex;i>firstIndex;i--)
					{
						var favor=jsresult[i];
						//选中状态
						window.parent.document.frames["mainFrame"].addSelect3D(favor.HID);						
						addItem(favor.HID,favor.premise);		
						addSubItem3(favor.area,favor.housePrice,favor.type,favor.location,favor.arrow,favor.floor); 
					}
					
					addEvent();						
				});		
								
			}
			else
			{
				alert("您还没有登录，请登录");
			}
		});
		
	
	//***********Search Button**************
	jQuery(window.parent.frames["LeftFrame"].document).find("#SearchButton").click(function(){
		//弹出查询结果的框	
					removeItems();	
					destroyEvent();					
					jQuery(window.parent.document).find("#rightFrame").fadeIn(1000);
					//取消所有选中状态
					window.parent.document.frames["mainFrame"].removeSelect3D();
					//标题	
					jQuery(window.parent.frames["rightFrame"].document).find(".titleBox").html("房屋搜索");		
				//Button Toggle
				$( "#toggle" ).button().toggle(function() {
				$( "#accordion" ).accordion( "option", "icons", false );
					}, function() {
				$( "#accordion" ).accordion( "option", "icons", icons );
					});	
				//End Button toggle					
				//jQuery(window.parent.frames["rightFrame"].document).find("#SPIC").attr("display","block");					
					jQuery(window.parent.document).find("#rightFrame").animate({ width: 240}, 1000 );
					jQuery(window.parent.frames["rightFrame"].document).find("#SPIC").attr("src","images/rightslide.png");	
					//情况原来的查询结果					
					//jQuery("h3").remove();
					//jQuery(".subItemStyle").remove();
					var kw=jQuery(window.parent.frames["LeftFrame"].document).find("#Search").attr("value");
						
					 var keyword={
						 "keyword":kw
						 };
				$.post("http://localhost:8090/RealHouse/Search",JSON.stringify(keyword),function(data){
				///alert(kw);
				    
				    
					var jsresult=$.parseJSON(data);	
					var totalSize=jsresult.length;
					//alert(jsresult[totalSize-1].SearchType);
					var searchTypeAll=null;
					var searchType0=null;
					searchTypeAll=jsresult[totalSize-1].SearchType;
					searchType0=jsresult[totalSize-1].SearchType[0];
					//alert("searchType0:"+searchType0+"    searchTypeAll:"+searchTypeAll);
					if(searchTypeAll=="AREA")
					{
						//alert("equal");
						jQuery(window.parent.frames["rightFrame"].document).find(".titleBox").html("您搜索类型是不是\"面积\"");	
					}
					else if(searchTypeAll=="PRICE")
					{
						jQuery(window.parent.frames["rightFrame"].document).find(".titleBox").html("您搜索类型是不是\"价格\"");	
					}
					else if(searchType0=="TYPE")
					{
						jQuery(window.parent.frames["rightFrame"].document).find(".titleBox").html("您搜索类型是不是\"户型\"");	
					}
					else if(searchType0=="FLOOR")
					{
						jQuery(window.parent.frames["rightFrame"].document).find(".titleBox").html("您搜索类型是不是\"楼层\"");	
					}
					else if(searchType0=="LOCATION")
					{
						jQuery(window.parent.frames["rightFrame"].document).find(".titleBox").html("您搜索类型是不是\"区域\"");	
					}
					else{};
					
					
					var len=null;
					if(jsresult!=null)
					{						
						if(jsresult.length<=10)
						{
							len=jsresult.length;
							
						}
						else
						{
							len=10;
						}
						
						for(var i=0;i<len;i++)
						{							
							//str+=jsresult[i].premise;
							//选中状态
							window.parent.document.frames["mainFrame"].addSelect3D(jsresult[i].HID);
							addItem(jsresult[i].HID,jsresult[i].premise);		
							addSubItem3(jsresult[i].area,jsresult[i].housePrice,jsresult[i].type,jsresult[i].location,jsresult[i].arrow,jsresult[i].floor);				
						}					 			
					}
					else
					{
						alert("请输入查询关键字，或者输入的关键字有误！");
					}					
					}).complete(function(){											
					addEvent();					
				});	
			
		
	
	});
	//End search button
		$("#switchBar").mouseover(function(){			
			$("#switch").css("display","block");				
				
		}); 	 		
		  
		$("#switchBar #switch").mouseout(function(){
			$("#switch").fadeOut("slow");
			
		});
		$("#switch").click(function(){
			//$("#switch").css("background","#111");
			var imgsrc=$("#SPIC").attr("src");
			if(imgsrc=="images/leftslide2.png")
			{
				//左滑出
				jQuery(window.parent.document).find("#rightFrame").animate({ width: 240}, 1000 );
				$("#SPIC").attr("src","images/rightslide.png");			
				
			}
			else
			{
				//右滑入
				jQuery(window.parent.document).find("#rightFrame").animate({ width: 20}, 1000 );
				$("#SPIC").attr("src","images/leftslide2.png");			
				
			}	
			});
		//End 窗体特效
		
		
		
		//Close the Window
		$("#leave").mouseover(function(e){
			var x = 5;     
    		var y = 5; 
			var tooltip="<div id='tooltip'>"+ this.title +"<\/div>"
			$("#list").append(tooltip);				
			 $("#tooltip")   
            .css({	
									
                "top": (e.pageY +y) + "px",   
                "left": (e.pageX +x) + "px"  
            }).show("fast"); 
			 $("#leave").css("top",3);
			});
		$("#leave").mouseout(function(){
			 $("#tooltip").remove(); 
			 $("#leave").css("top",0);
			});
		$("#leave").click(function(){
			jQuery(window.parent.document).find("#rightFrame").fadeOut(2000);			
			});	
	});
	
		
	</script>
</head>
<body bgcolor="#bbbbbb">

<button class="titleBox" id="toggle">信息窗</button>

<div id="switchBar" class="leftBox">
<div>
<img id="leave" class="closeBox" src="images/close3.png" title="隐藏此页">
</div>
<div id="switch" class="imgBox">
<img id="SPIC" src="images/rightslide.png" height="60" width="30"/> 
</div>
</div>
<div class="demo">
<div id="accordion">

</div>
<!--
<button id="toggle">Toggle icons</button>
-->
</div><!-- End demo -->
</body>
</html>
